#pragma once

#include <CoreWindow.h>
#include <cassert>

namespace my
{
	template<class T>
	class console_screen_frame_base
	{
		template<class Type, class CH, class STRING>
		friend class console_screen_frame;

		template<class PFUNC, class MENU, class FRAME, class CHAR, class STRING>
		friend class console_screen;

		template<class TEXTCHAR, class FRAME, class STRING, class CHAR>
		friend class console_screen_text;

	public:

		console_screen_frame_base(int x = 0, int y = 0, int high = 5, int wide = 10,
			T up = 0, T down = 0, T left = 0, T right = 0,
			T top_left = 0, T bottom_left = 0, T top_right = 0, T bottom_right = 0)
			:_x(x)
			, _y(y)
			, _high(high)
			, _wide(wide)
			, _up(up)
			, _down(down)
			, _left(left)
			, _right(right)
			, _top_left(top_left)
			, _bottom_left(bottom_left)
			, _top_right(top_right)
			, _bottom_right(bottom_right)
		{
			assert(x >= 0 && y >= 0);
			assert(high >= 0 && wide >= 0);
		}

		void changePos(int x, int y)
		{
			assert(x >= 0 && y >= 0);

			_x = x;
			_y = y;
		}

		void changeFrameSize(int high, int wide)
		{
			assert(high >= 0 && wide >= 0);

			_high = high;
			_wide = wide;
		}

		void changeSide(T up = 0, T down = 0, T left = 0, T right = 0)
		{
			_up = up == 0 ? _up : up;
			_down = down == 0 ? _down : down;
			_left = left == 0 ? _left : left;
			_right = right == 0 ? _right : right;
		}

		void changeCorner(T top_left = 0, T bottom_left = 0, T top_right = 0, T bottom_right = 0)
		{
			_top_left = top_left == 0 ? _top_left : top_left;
			_bottom_left = bottom_left == 0 ? _bottom_left : bottom_left;
			_top_right = top_right == 0 ? _top_right : top_right;
			_bottom_right = bottom_right == 0 ? _bottom_right : bottom_right;
		}

		void changeUp(T up)
		{
			_up = up;
		}

		void changeDown(T down)
		{
			_down = down;
		}

		void changeLeft(T left)
		{
			_left = left;
		}

		void changeRight(T right)
		{
			_right = right;
		}

		void changeTopLeft(T top_left)
		{
			_top_left = top_left;
		}

		void changeTopRight(T top_right)
		{
			_top_right = top_right;
		}

		void changeBottomLeft(T bottom_left)
		{
			_bottom_left = bottom_left;
		}

		void changeBottomRight(T bottom_right)
		{
			_bottom_right = bottom_right;
		}

	protected:

		void printFrame()
		{
			if (_up != 0)
			{
				printCharUp();
			}
			if (_down != 0)
			{
				printCharDown();
			}
			if (_left != 0)
			{
				printCharLeft();
			}
			if (_right != 0)
			{
				printCharRight();
			}
			if (_top_left != 0 ||
				_top_right != 0 ||
				_bottom_left != 0 ||
				_bottom_right != 0)
			{
				printCharCorner();
			}
		}

		virtual void printCharUp() = 0;

		virtual void printCharDown() = 0;

		virtual void printCharLeft() = 0;

		virtual void printCharRight() = 0;

		virtual void printCharCorner() = 0;

		void cleanFrame()
		{
			if (_up != 0)
			{
				cleanCharUp();
			}
			if (_down != 0)
			{
				cleanCharDown();
			}
			if (_left != 0)
			{
				cleanCharLeft();
			}
			if (_right != 0)
			{
				cleanCharRight();
			}
			if (_top_left != 0 ||
				_top_right != 0 ||
				_bottom_left != 0 ||
				_bottom_right != 0)
			{
				cleanCharCorner();
			}
		}

		virtual void cleanCharUp() = 0;

		virtual void cleanCharDown() = 0;

		virtual void cleanCharLeft() = 0;

		virtual void cleanCharRight() = 0;

		virtual void cleanCharCorner() = 0;

	protected:

		short _x;
		short _y;

		short _high;
		short _wide;

		T _up;
		T _down;
		T _left;
		T _right;

		T _top_left = 0;
		T _bottom_left = 0;
		T _top_right = 0;
		T _bottom_right = 0;
	};
}



